<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>User Table</title>
    <style>
      table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>价格</th>
                <th>库存</th>
            </tr>
        </thead>
        <tbody>

           
        </tbody>
    </table>
    <script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
    <script>
      
        $.ajax({
        type: 'get',
        url: 'http://localhost:3000/users/list',
        dataType: 'json',
        headers:{
            Authorization:`Bearer `+ localStorage.getItem("token")
        },
        success: function(data) {
            console.log(data);
            $('tbody').html('')
                data.data.forEach(item => {
                    $('tbody').append(`
                    <tr>
                    <td>${item.id}</td>
                    <td>${item.name}</td>
                    <td>${parseFloat(item.price)}</td>
                    <td>${parseFloat(item.stock)}</td>
                   
                     </tr>
                    
                    `)
                });
            
        },
        error: function(err) {
            console.log(err);
        }
    });



    </script>
</body>
</html>